package com.ruoyi.common.utils.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.ruoyi.common.utils.BigDecimalUtils;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * BigDecimal序列化为plainString
 *
 * @date 2022/8/24 22:11
 */
public class BigDecimalToPlainStringSerializer extends JsonSerializer<BigDecimal> {
	/**
	 * BigDecimal反序列化器
	 *
	 * @param value
	 * @param jsonGenerator
	 * @param serializerProvider
	 * @date 2022/8/24 22:15
	 */
	@Override
	public void serialize(BigDecimal value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
		String s = BigDecimalUtils.toStrRemoveExtraZero(value);
		jsonGenerator.writeString(s);
	}
}
